package canglang.monitor.cases.service.impl;

import canglang.monitor.cases.dao.CaseSixDAO;
import canglang.monitor.cases.model.CaseSixModel;
import canglang.monitor.cases.model.CaseLightModel;
import canglang.monitor.cases.service.CaseSixMgr;
import canglang.monitor.cases.service.CaseLightMgr;
import canglang.monitor.cases.to.SearchSixTO;
import canglang.monitor.core.base.pagination.PaginatedListHelper;
import canglang.monitor.core.base.util.DateUtil;

import java.util.List;
import java.util.Date;

public class CaseSixMgrImpl implements CaseSixMgr {

	private CaseSixDAO caseSixDAO;

    private CaseLightMgr caseLightMgr;

    public void setCaseLightMgr(CaseLightMgr caseLightMgr) {
        this.caseLightMgr = caseLightMgr;
    }

	public void setCaseSixDAO(CaseSixDAO caseSixDAO) {
		this.caseSixDAO = caseSixDAO;
	}

	public CaseSixModel addCaseSix(CaseSixModel caseSixModel) {
		int id=caseSixDAO.addCaseSix(caseSixModel);
        CaseLightModel caseLightModel = new CaseLightModel();
        caseLightModel.setCaseType("06");
        caseLightModel.setCaseId(id);
        caseLightModel.setDeptId(caseSixModel.getDeptId());
        caseLightModel.setPplInd("N");
        caseLightModel.setProcInd("N");
        caseLightModel.setLightInd("N");
        Date date = DateUtil.getDate();
        caseLightModel.setCreateId(caseSixModel.getCreateId());
        caseLightModel.setUpdateId(caseSixModel.getCreateId());
        caseLightModel.setCreateDt(date);
        caseLightModel.setUpdateDt(date);
        caseLightMgr.addCaseLight(caseLightModel);
		return caseSixDAO.getCaseSix(id);
	}

	public CaseSixModel getCaseSix(int caseSixId) {
		return caseSixDAO.getCaseSix(caseSixId);
	}

	public CaseSixModel saveCaseSix(CaseSixModel caseSixModel) {
        caseLightMgr.updateLightDept("06",caseSixModel.getCaseSixId(),caseSixModel.getDeptId());
        return caseSixDAO.saveCaseSix(caseSixModel);
	}

	public void deleteCaseSix(int caseSixId) {
        caseLightMgr.deleteUnuseLight("06",caseSixId);
        caseSixDAO.deleteCaseSix(caseSixId);
	}

    public PaginatedListHelper search(PaginatedListHelper helper, SearchSixTO searchTO){
        int count = caseSixDAO.searchCount(searchTO);
        helper.setFullListSize(count);
        List list = caseSixDAO.searchList(helper, searchTO);
        helper.setList(list);
        return helper;
    }

     public List getCaseSixList(SearchSixTO searchTO){
        return caseSixDAO.getCaseSixList(searchTO);
    }
}
